import jqdatasdk
import pandas
from stocksys.quant_tactics.RuleExcuter import StockInfo
from stocksys.tasks_function.serialization_data import load_train_data_by_year
from django.contrib.auth import models as auth_models
import datetime
import time, numpy
from stocksys import models as stocksys_models


# MACD指标
class KDJ:
    pass


class MACD:
    MA90 = None
    MA30 = None
    MA5 = None
    MA3 = None


# 傅里叶指标
class FFT:
    Freq = None


class BaseIndex:
    MACD = MACD()
    FFT = FFT()
    KDJ = KDJ()


# 控制模块
class Control:
    available_cash = 0.0  # 现金量
    origin_capital = 0.0  # 初始资金
    positions_value = 0.0  # 剩余资金
    time_now = None
    bse_index = BaseIndex()  # 基本指标
    trade = False  # 开启实盘
    open_interest = []  # 持仓
    select_stock = []  # 持仓

    def __init__(self, user: stocksys_models.SysConf):
        self.available_cash = user.my_capital
        self.origin_capital = user.my_capital
        self.positions_value = user.my_capital

    def order_buy(self, exchange):
        pass

    def order_sell(self, exchange):
        pass

    def send_message(self, title, content):
        pass

    def set_benchmark(self, exchange: stocksys_models.Stock):
        pass

    def get_value(self):
        '''
        获取当前市值
        :return: float value
        '''
        value = 0
        for ids in range(len(self.select_stock)):
            _stock_number = self.select_stock[ids].number
            _stock_order_price = self.select_stock[ids].order_price
            _stock_current_price = self.select_stock[ids].current_price
            value += _stock_current_price * _stock_number
        return value

    def get_report(self):
        get_open_intrest_profit_and_loss = self.origin_capital - (self.positions_value + self.get_value())


class SimulateControl(Control):
    def order_buy(self, exchange):
        pass

    def order_sell(self, exchange):
        pass


class RealControl(Control):
    def order_buy(self, exchange):
        pass

    def order_sell(self, exchange):
        pass

    def send_message(self, title, content):
        pass
